package com.cq.hd.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cq.hd.common.utils.BeanUtils;
import com.cq.hd.member.api.dto.PopRecordDto;
import com.cq.hd.member.api.dto.PopRecordSaveDto;
import com.cq.hd.member.api.vo.PopRecordVo;
import com.cq.hd.member.po.TbPopRecordPo;
import com.cq.hd.member.mapper.TbPopRecordMapper;
import com.cq.hd.member.service.TbPopRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 弹窗记录表 服务实现类
 * </p>
 *
 * @author mYunYu
 * @since 2024-01-03
 */
@Service
public class TbPopRecordServiceImpl extends ServiceImpl<TbPopRecordMapper, TbPopRecordPo> implements TbPopRecordService {

    @Override
    public Boolean savePopRecord(PopRecordSaveDto popRecordSaveDto) {
        Integer count = baseMapper.selectCount(new QueryWrapper<TbPopRecordPo>()
                .eq("platform_type", popRecordSaveDto.getPlatformType())
                .eq("pop_type", popRecordSaveDto.getPopType())
                .eq("user_id", popRecordSaveDto.getUserId()));
        if (count != null && count > 0) {
            return false;
        }

        TbPopRecordPo tbPopRecordPo = new TbPopRecordPo();
        BeanUtils.copyProperties(popRecordSaveDto, tbPopRecordPo);
        baseMapper.insert(tbPopRecordPo);

        return true;
    }

    @Override
    public List<PopRecordVo> listByDto(PopRecordDto popRecordDto) {
        return baseMapper.listByDto(popRecordDto);
    }
}
